package com.jic.manager.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jic.common.utils.HttpClientUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 公共发送短信类
 * @author wwb
 */
@Slf4j
@Component
public class SmsUtils {

    @Value("${sms.url}")
    private String smsUrl;

    @Value("${sms.accessKey}")
    private String accessKey;

    private String successCode = "0";

    /**
     * 发送短信
     * @param phone
     * @return
     */
    public Boolean sendSms(String phone , String tempId , Map<String,String> context) throws Exception{
        JSONObject params = new JSONObject();
        params.put("params", context);
//        params.put("receiver",phone);
        params.put("receiver","18616395304");
        params.put("accessKey",accessKey);
        params.put("tempId",tempId);
        log.info("发送短信： 请求参数=============>>>>{}",JSONArray.toJSONString(params));
        HttpClientUtils.setHeader(new HashMap<String, String>(2){{
            put("Content-Type","application/json;charset=UTF-8");
//                put("Accept","application/json");
        }});
//        String rest = HttpClientUtils.doPostJson(smsUrl, params);
////        log.info("发送短信成功===》》》》{}",rest);
////        if(StringUtils.isNotEmpty(rest)){
////            String code = JSONArray.parseObject(rest, Map.class).get("code").toString();
////            if(successCode.equals(code)){
////                return true;
////            }else{
////                return false;
////            }
////        }else{
////            log.error("短信发送失败=====》》》》返回值为null");
////            return false;
////        }
        return true;
    }
}
